#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Net;
#endregion

namespace PFAGame
{
    class MainMenuScreen : MenuScreen
    {
        #region Initialization


        public MainMenuScreen()
            : base(Resources.MainMenu)
        {
            // Create our menu entries.
            MenuEntry singlePlayerMenuEntry = new MenuEntry(Resources.SinglePlayer);
            //MenuEntry liveMenuEntry = new MenuEntry(Resources.PlayerMatch);
            MenuEntry systemLinkMenuEntry = new MenuEntry(Resources.SystemLink);
            MenuEntry optionMenuEntry = new MenuEntry(Resources.Option);
            MenuEntry exitMenuEntry = new MenuEntry(Resources.Exit);

            // Hook up menu event handlers.
            singlePlayerMenuEntry.Selected += SinglePlayerMenuEntrySelected;
           // liveMenuEntry.Selected += LiveMenuEntrySelected;
            systemLinkMenuEntry.Selected += SystemLinkMenuEntrySelected;
            optionMenuEntry.Selected += optionMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(singlePlayerMenuEntry);
            //MenuEntries.Add(liveMenuEntry);
            MenuEntries.Add(systemLinkMenuEntry);
            MenuEntries.Add(optionMenuEntry);
            MenuEntries.Add(exitMenuEntry);

            SoundManager.Singleton.PlayMusic(3);
        }


        #endregion

        #region Handle Input

        void SinglePlayerMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.AddScreen(new GameModeMenuScreen(), e.PlayerIndex);
        }


        void optionMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }

        //void LiveMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        //{
        //    CreateOrFindSession(NetworkSessionType.PlayerMatch, e.PlayerIndex);
        //}


        void SystemLinkMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            CreateOrFindSession(NetworkSessionType.SystemLink, e.PlayerIndex);
        }


        void CreateOrFindSession(NetworkSessionType sessionType,
                                 PlayerIndex playerIndex)
        {
            ProfileSignInScreen profileSignIn = new ProfileSignInScreen(sessionType);

            profileSignIn.ProfileSignedIn += delegate
            {
                GameScreen createOrFind = new CreateOrFindSessionScreen(sessionType);

                ScreenManager.Singleton.AddScreen(createOrFind, playerIndex);
            };

            ScreenManager.Singleton.AddScreen(profileSignIn, playerIndex);
        }


        protected override void OnCancel(PlayerIndex playerIndex)
        {
            MessageBoxScreen confirmExitMessageBox =
                                    new MessageBoxScreen(Resources.ConfirmExitSample);

            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;

            ScreenManager.Singleton.AddScreen(confirmExitMessageBox, playerIndex);
        }


        void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.Game.Exit();
        }


        #endregion

        
    }
}
